#include <iostream>
using namespace std;
struct Node
{
    Node *next;
    int N;
    double a;
};
int main()
{
    int n;
    Node head1, head2;
    Node *node, *t, *p, *pre, *pp, *head;
    head1.next = NULL;
    head2.next = NULL;
    cin >> n;
    t = &head1;
    while (n--)
    {
        node = (Node *)malloc(sizeof(Node));
        cin >> node->N >> node->a;
        if (node->a == 0)
            continue;
        node->next = NULL;
        t->next = node;
        t = t->next;
    }
    cin >> n;
    t = &head2;
    while (n--)
    {
        node = (Node *)malloc(sizeof(Node));
        cin >> node->N >> node->a;
        if (node->a == 0)
            continue;
        node->next = NULL;
        t->next = node;
        t = t->next;
    }
    if (head1.next->N < head2.next->N)
    {
        t = head2.next;
        p = head1.next;
    }
    else
    {
        t = head1.next;
        p = head2.next;
    }
    head = t;
    // first t is bigger than first p
    while (t != NULL && p != NULL)
    {
        if (t->N == p->N)
        {
            t->a += p->a;
            pre = t;
            t = t->next;
            p = p->next;
        }
        else if (t->N > p->N)
        {
            pre = t;
            t = t->next;
        }
        else
        {
            pp = p;
            p = p->next;
            pp->next = t;
            pre->next = pp;
            pre = pp;
        }
    }
    if (p != NULL)
    {
        pre->next = p;
    }
    t = head;
    int count = 0;
    while (t != NULL)
    {
        if (t->a != 0)
            count++;
        t = t->next;
    }
    cout << count;
    t = head;
    while (t != NULL)
    {
        if (t->a != 0)
            printf(" %d %.1f", t->N, t->a);
        t = t->next;
    }
    return 0;
}